import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:liuxlcommon/lget/lget.dart';
import 'package:liuxlcommon/view/lxl_widget.dart';
import 'package:liuxlcommon/view/my_box.dart';
import 'package:love_newf/app/com/base/L.dart';
import 'package:love_newf/app/com/view/label/province_label.dart';
import 'package:love_newf/app/com/view/label/sex_label.dart';
import 'package:love_newf/app/com/view/label/vip_grade_label.dart';
import 'package:love_newf/app/com/view/webview/my_web/my_web_page.dart';
import 'package:love_newf/app/page/home/home_listener.dart';
import 'package:love_newf/app/page/home/home_logic.dart';
import 'package:love_newf/app/page/mine/real_name_auth/real_name_auth_page.dart';
import 'package:love_newf/app/page/mine/setting/setting_view.dart';
import 'package:love_newf/generated/assets.dart';
import 'package:love_newf/value/app_const.dart';
import 'about/about_page.dart';
import 'complaint/complaint_page.dart';
import 'mine_logic.dart';

class MinePage extends StatefulWidget {
  const MinePage({Key? key}) : super(key: key);

  @override
  _MinePageState createState() => _MinePageState();
}

class _MinePageState extends State<MinePage>
    with AutomaticKeepAliveClientMixin, HomeListener {
  final logic = Get.put(MineLogic());
  final GlobalKey<RefreshIndicatorState> _indicatorKey =
      GlobalKey<RefreshIndicatorState>();

  @override
  void initState() {
    super.initState();
    Get.find<HomeLogic>().mapHomeListener["mine"] = this;
    onHomePageChanged(1);
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Scaffold(
        backgroundColor: const Color(0xFFF7F7F9),
        body: GetBuilder<MineLogic>(
            builder: (l) =>
                ListView(padding: EdgeInsets.zero, children: [body])));
  }

  get body => LColumn.eazy([
        topUserBox,
        // commFuncBox,
        12.lsh,
        moreFuncBox
      ]).size(Get.width, null);

  get commFuncBox => LContainer(
              child: Wrap(children: [
        LText.easy("常用功能", 14.w, fw5).paddingAll(13.w).size(330.w, null),
        itemCommFunc("我的钱包", Assets.funcMineMyWalletIc, null),
        itemCommFunc("装扮中心", Assets.funcMineZhuangban, null),
        itemCommFunc("我的玫瑰", Assets.funcMineRose, null),
        itemCommFunc("玫瑰兑换", Assets.funcMineRoseChange, null),
        itemCommFunc("美颜调整", Assets.funcMineBeautity, null),
        itemCommFunc("红娘后台", Assets.funcIconMineMatchmaker, null),
        itemCommFunc("基本资料", Assets.funcMineBasicData, null),
        itemCommFunc("我的情侣", Assets.funcIcMineLover, null),
      ]))
          .padding(bottom: 10.w)
          .bgColor(Colors.white)
          .radius(14.w)
          .size(353.w, null);

  get moreFuncBox => LColumn.eazy([
        // itemMoreFunc("我的客服", null),
        // itemMoreFunc("认证中心", null),
        // itemMoreFunc("投诉反馈", null),
        // itemMoreFunc("常见问题", null),

        LRow.eazy([
          10.lsw,
          LText.easy("实名认证", 14.w).flex(1),
          const Icon(Icons.chevron_right, color: Colors.grey)
        ]).paddingAll(12.w).onTapL(() {
          Get.to(RealNameAuthPage());
        }),

        itemMoreFunc("投诉反馈", () => Get.to(ComplaintPage())),
        itemMoreFunc("关于我们", () => Get.to(AboutPage())),
        itemMoreFunc("隐私政策", () {
          Get.to(MyWebPage(url: "https://pinv.whhyn.shop/c.html"));
        }),
        itemMoreFunc("设置", () => Get.to(SettingPage())),
      ]);

  itemCommFunc(name, img, onTap) {
    return LColumn.eazy([
      LImage.easy(img, 28.w, 20.w),
      4.lsh,
      LText.easy(name, 12.w),
    ]).center().size(352.w / 4, 70.w);
  }

  itemMoreFunc(name, onTap) {
    return LRow.eazy([
      10.lsw,
      LText.easy(name, 14.w).flex(1),
      const Icon(Icons.chevron_right, color: Colors.grey)
    ]).paddingAll(12.w).onTapL(onTap);
  }

  get topUserBox => LRow.eazy([
        LImage.easy(L.userInfo.avatar, 75.w, 75.w, 75.w),
        12.lsw,
        LColumn.eazy([
          LText.easy(L.userInfo.nick, 15.w, fw5),
          7.lsh,
          LRow.eazy([
            LText.easy(" ID ", 11.w, fw8, Colors.white)
                .radius(6.5.w)
                .bgColor(const Color(0xFFCED9EA)),
            LText.easy(L.userInfo.userCode, 12.w, fw8, const Color(0xFF9E9E9E))
          ]),
          4.lsh,
          LRow.eazy([
            SexAgeLabel(L.userInfo.sex, L.userInfo.age),
            4.lsw,
            ProvinceLabel(L.userInfo.province),
            4.lsw,
            VipGradeLabel(L.userInfo.vipGrade)
          ]),
        ]).align(Alignment.topLeft).flex(1),
        const Icon(Icons.chevron_right, color: Colors.grey)
      ]).padding(left: 11.w, right: 11.w, top: 50.w, bottom: 30.w);

  @override
  void dispose() {
    Get.delete<MineLogic>();
    super.dispose();
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void onHomePageChanged(position) {
    if (position != 1) return;
    //已经加载完成，需要做刷新
    if (logic.mineMenus != null) {
      _indicatorKey.currentState?.show();
    }
  }
}
